package com.example.cloud.controller;

import com.example.cloud.service.FlowLimitService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @author 一朝风月
 * @date 2024/3/17 15:52
 * description
 */
@RestController
public class FlowLimitController {
    @GetMapping("/test1")
    public String test01(){
        return "----test01";
    }
    @GetMapping("/test2")
    public String test02(){
        return "----test2";
    }
    @Resource
    private FlowLimitService flowLimitService;

    @GetMapping("/testC")
    public String testC()
    {
        flowLimitService.common();
        return "------testC";
    }
    @GetMapping("/testD")
    public String testD()
    {
        flowLimitService.common();
        return "------testD";
    }
    //流控效果等待
    @GetMapping("/testE")
    public String testE(){
//        flowLimitService.common();
        System.out.println(System.currentTimeMillis()+"     TestE等待时长");
        return "------------testE";
    }
    @GetMapping("/testF")
    public String testF(){
        try {
            //1线程等待1s
            TimeUnit.SECONDS.sleep(1);
        }catch (Exception e){
            e.printStackTrace();
        }
        System.out.println("测试新增熔断规则-慢调用比例");
        return "-------------testF新增熔断规则慢调用比例";
    }
    //新增熔断规则 异常比例
    @GetMapping("/testG")
    public String testG(){
        System.out.println("测试：新增熔断规则-异常");
        int age=10/0;
        return "----------testG,新增熔断规则-异常比例";
    }
    //新增熔断规则异常数
    @GetMapping("/testH")
    public String testH(){
        System.out.println("测试：新增熔断规则-异常");
        int age=10/0;
        return "----------testG,新增熔断规则-异常数";
    }
}
